package com.levi.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建死信队列交换机
 * 死信队列交换机也是一个正常的交换机，只是将其绑定到其他的队列上，将过期的消息放到这个交换机里面，
 * 随后按照业务需求将死信队列里面的消息进行处理
 * 死信队列相当于是一个接盘侠
 */
@Configuration
public class DeadMsgQueue {

    @Bean
    public Queue deadQueue() {
        return new Queue("deadqueue");
    }

    @Bean
    public TopicExchange deadTopicExchange() {
        return new TopicExchange("deadTopicExchange");
    }

    @Bean
    public Binding Deadbindings(Queue deadQueue,TopicExchange deadTopicExchange) {
        return BindingBuilder.bind(deadQueue)
                .to(deadTopicExchange)
                .with("dead");
    }


}
